function custom_profile = sine_wave_temp_oddball(base_temp, common_temp, rare_temp, period, num_of_waves, oddball_appearance)
% SINE_WAVE creates a custom profile in TCS format of a semi-sine wave,
% repeated multiple amount of times

% base_temp and max_temp in °C
% period in seconds

%% Data Amount
segments_per_wave = 20 ; % Number of segments to send to the TCS
% Reduce this number to make a less detailed but faster-to-send profile.
total_segment_number = segments_per_wave*num_of_waves ;                                                                                    % The number of segments in total
if total_segment_number > 999   % The TCS can only handle up to 999 segments in its 'Uw...' command.
    error('Warning : There are too many segments in the custom profile for the TCS to handle, please reduce the variable ''Segments'' in the ''sine_wave'' function.') ;
end
%% The Profile
time_bin_length = round(100 * period / segments_per_wave) ;   % The duration of each segment in 10ms
common_wave = round((sin(pi * (1:segments_per_wave) / segments_per_wave) * (common_temp - base_temp) + base_temp) * 10) ;     % Generates the temperature commands for one common wave 
rare_wave = round((sin(pi * (1:segments_per_wave) / segments_per_wave) * (rare_temp - base_temp) + base_temp) * 10) ;     % Generates the temperature commands for one rare wave 
temp_profile = zeros(1,total_segment_number);
for i = 1:num_of_waves
    if rem(i, oddball_appearance) == 0
        temp_profile((i*segments_per_wave-segments_per_wave+1):i*segments_per_wave) = rare_wave;
    else
        temp_profile((i*segments_per_wave-segments_per_wave+1):i*segments_per_wave) = common_wave;
    end
end
Wave_Data = zeros(1, 2*total_segment_number);               % Pre-allocation for speed interests
Wave_Data(1:2:end)= time_bin_length ;               % every odd triplet is the duration of the segment in 10 of milliseconds
for i=1:total_segment_number                                % every even triplet is the temperature command in 10th of °C
    Wave_Data(2*i) = temp_profile(i);                           % For more details, see 'TCS_Commands.txt'
end
custom_profile = ['Uw11111' sprintf('%03d',total_segment_number) sprintf('%03d', Wave_Data(:))];
end

